<template>
  <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
    <h2 class="sub-header">添加学生</h2>
    <input type="hidden" name="id" v-model="student.id" />
    <div class="form-group">
      <label for>姓名</label>
      <input
        type="text"
        class="form-control"
        id
        name="name"
        required
        minlength="2"
        maxlength="10"
        v-model="student.name"
      />
    </div>
    <div class="form-group">
      <label for>性别</label>
      <div>
        <label class="radio-inline">
          <input type="radio" name="gender" v-model="student.gender" value="0" /> 男
        </label>
        <label class="radio-inline">
          <input type="radio" name="gender" id v-model="student.gender" value="1" /> 女
        </label>
      </div>
    </div>
    <div class="form-group">
      <label for>年龄</label>
      <input
        class="form-control"
        type="number"
        id
        name="age"
        v-model="student.age"
        required
        min="1"
        max="150"
      />
    </div>
    <div class="form-group">
      <label for>爱好</label>
      <input class="form-control" type="text" id name="hobbies" v-model="student.hobbies" />
    </div>
    <button class="btn btn-default" @click="editEvent">提交</button>
  </div>
</template>
<script>
import { Toast } from "mint-ui";
export default {
  data() {
    return {
      student: {}
    };
  },
  methods: {
    getStudent() {
      this.$http
        .get("/students/edit", { params: { id: this.$route.params.id } })
        .then(response => {
          this.student = response.body;
        });
    },
    editEvent() {
      var formData = JSON.stringify(this.student);
      this.$http.post("/students/edit", formData).then(() => {
        this.$parent.getStudents();
        Toast({
          message: "修改信息成功！",
          position: "middle",
          duration: 1000,
          iconClass: "glyphicon glyphicon-ok"
        });
        this.$router.push("/students");
      });
    }
  },
  created() {
    this.getStudent();
  }
};
</script>
<style>
</style>
